/*     */ package com.newcrm.webapi.sub;
/*     */ 
/*     */ import com.newcrm.bean.CompanyInfo;
/*     */ import com.newcrm.bean.User;
/*     */ import com.newcrm.db.CompanyExtManager;
/*     */ import com.newcrm.exception.NotFoundException;
/*     */ import com.newcrm.util.Util;
/*     */ import com.newcrm.webapi.AbstractAction;
/*     */ import com.newcrm.webapi.AbstractHttpServlet;
/*     */ import java.io.IOException;
/*     */ import java.io.PrintWriter;
/*     */ import java.net.URLEncoder;
/*     */ import javax.servlet.ServletException;
/*     */ import javax.servlet.http.HttpServletRequest;
/*     */ import javax.servlet.http.HttpServletResponse;
/*     */ import net.sf.json.JSONObject;
/*     */ import org.apache.log4j.Logger;
/*     */ import org.jsoup.Connection;
/*     */ import org.jsoup.Jsoup;
/*     */ import org.jsoup.nodes.Document;
/*     */ 
/*     */ public class QisoukeActiveCode extends AbstractAction
/*     */ {
/*  34 */   private static Logger logger = Logger.getLogger(QisoukeActiveCode.class
/*  35 */     .getName());
/*     */ 
/*     */   public QisoukeActiveCode(AbstractHttpServlet servlet)
/*     */   {
/*  38 */     super(servlet);
/*     */   }
/*     */ 
/*     */   public void parse(HttpServletRequest request, HttpServletResponse response)
/*     */     throws IOException, ServletException, NotFoundException
/*     */   {
/*  45 */     String activeCode = Util.getURLParameter(request
/*  46 */       .getParameter("activeCode"));
/*  47 */     if ((activeCode == null) || (activeCode.trim().length() == 0)) {
/*  48 */       super.showErrorMessage(response, "请输入激活码");
/*  49 */       return;
/*     */     }
/*     */ 
/*  52 */     User u = super.getLoginUser(request);
/*  53 */     CompanyInfo company = super.getCompany(request);
/*     */ 
/*  55 */     StringBuffer searchUrl = new StringBuffer();
/*  56 */     searchUrl
/*  57 */       .append("http://so.qikebao.com/qisoukeActivation/serial?serialId=")
/*  58 */       .append(URLEncoder.encode(activeCode, "UTF-8"))
/*  59 */       .append("&companyName=")
/*  60 */       .append(URLEncoder.encode(company.name, "UTF-8"))
/*  61 */       .append("&createDate=")
/*  62 */       .append(URLEncoder.encode(Util.date2Str(company.createDate), 
/*  63 */       "UTF-8"));
/*     */ 
/*  65 */     response.setContentType("text/html;charset=utf-8");
/*  66 */     PrintWriter out = response.getWriter();
/*     */ 
/*  68 */     Document doc = null;
/*     */     try {
/*  70 */       doc = Jsoup.connect(searchUrl.toString()).timeout(30000).get();
/*  71 */       out.println(doc.text());
/*     */     } catch (Exception e) {
/*  73 */       logger.warn("qisouke sn registe failed", e);
/*  74 */       super.showErrorMessage(response, "注册超时，请稍后再试");
/*  75 */       return;
/*     */     }
/*  77 */     JSONObject json = null;
/*     */     try {
/*  79 */       json = JSONObject.fromObject(doc.text());
/*     */     } catch (Exception e) {
/*  81 */       logger.warn("qisouke sn registe failed", e);
/*  82 */       super.showErrorMessage(response, "注册超时，请稍后再试");
/*  83 */       return;
/*     */     }
/*     */ 
/*  87 */     if ("0".equals(Util.getJSONStringValue(json, "error"))) {
/*  88 */       int userNum = Util.getJSONIntValue(json, "userNum");
/*     */ 
/*  90 */       CompanyExtManager manager = new CompanyExtManager();
/*     */ 
/*  93 */       company.qisoukeActivationCode.userNum = userNum;
/*  94 */       manager.update(10, 
/*  95 */         String.valueOf(userNum), u.companyId, u.userId);
/*     */ 
/*  98 */       company.qisoukeActivationCode.sn = activeCode;
/*  99 */       int result = manager.update(8, 
/* 100 */         activeCode, u.companyId, u.userId);
/*     */ 
/* 102 */       if (result != 1) {
/* 103 */         super.showErrorMessage(response, "注册信息设置失败，请稍后再试");
/* 104 */         return;
/*     */       }
/*     */     }
/* 107 */     out.flush();
/* 108 */     out.close();
/*     */   }
/*     */ }

/* Location:           C:\E\referenceProject\CRM参考\qikebao\WEB-INF\lib\qikebao.jar
 * Qualified Name:     com.newcrm.webapi.sub.QisoukeActiveCode
 * JD-Core Version:    0.6.1
 */